#delimit;
clear all;
set more off;

capture log using "08_DAF_Investment_Summary_Table.log", replace;

/*******************************************************************************************/;
** INPUT: (1) Hand-coded investment (i.e., securities) details from "03_Readin_Handcode_Investments_and_Classify.do";
** (2) DAF classification data from handcode from "02_Readin_Handcode_DAF_Classification.do" and;
** (3) Digitized DAF tax data from Guidstar from "01_Prepare_Guidestar_Basic.do";
** OUTPUT: Allocations and returns by DAF type and univariate tests (Tables 3 & 4 in paper);
** LAST MODIFIED: JAG, 1/24/2022;
** RUN TIME: <5 minutes using Stata 15 on computer with 2 x 2.60GHz processors and 64GB RAM;
/*******************************************************************************************/;

** Do DAFS that focus on longer-term issues match their securities and investment with what they say;
** E.g., do those focused on climate change choose investments with a longer duration;
** Do those focused on discrimination similarly choose investment with a longer duration;
** Or do those focused on discrimination and disparity seem to have more risky investments (e.g., hedge fund, PE);
** Or do they focus more on social investments;
** Are the returns realized on their gains higher? (this variable would come from the change in balance or is there an explicit return var?);

use "Securities with handcode for tables.dta", clear;
** Merge the security details with the DAF-type;
merge m:1 ein using "DAF classification clean.dta";
gen has_securities_data=(_m==3);
drop _m;
merge 1:1 ein year using "Main with additional details.dta";

** For now limiting to those with securities data;
count if has_securities_data==1 & _m!=3;
keep if has_securities_data==1 & _m==3;
drop _m;

** Start with basic descriptives for the DAFs with securities investment but excluding university endowments for now;
** These codes drop university endowments;
gen top20=0;
replace top20=1 if ein=="06-0646973";
replace top20=1 if ein=="94-1156365";
replace top20=1 if ein=="04-2103580";
replace top20=1 if ein=="21-0634501";
replace top20=1 if ein=="35-0868188";
replace top20=1 if ein=="36-2167817";
replace top20=1 if ein=="13-5598093";
replace top20=1 if ein=="23-1352685";
replace top20=1 if ein=="21-0634501";
replace top20=1 if ein=="02-0222111";
replace top20=1 if ein=="05-0258809";
replace top20=1 if ein=="04-2103594";
replace top20=1 if ein=="43-0653611";
replace top20=1 if ein=="95-2250801";
replace top20=1 if ein=="52-0595110";
replace top20=1 if ein=="04-2103542";
replace top20=1 if ein=="16-0743209";
replace top20=1 if ein=="95-1642394";
replace top20=1 if ein=="04-2104847";
replace top20=1 if ein=="59-0974739";
gen endow=(sic=="8221");

count;
codebook(ein);

** NEXT WE WANT TO GET BENCHMARK RETURNS;
** Equity benchmark is S&P 500 returns (https://www.macrotrends.net/2526/sp-500-historical-annual-returns);
gen eqty_bmk=0.2888 if year==2019;
replace eqty_bmk=-0.0624 if year==2018;
replace eqty_bmk=0.1942 if year==2017;
replace eqty_bmk=0.0954 if year==2016;
replace eqty_bmk=-0.0073 if year==2015;
replace eqty_bmk=0.1139 if year==2014;
replace eqty_bmk=0.296 if year==2013;

** Fixed income benchmark is US aggregtae bond index returns (https://finance.yahoo.com/quote/agg/performance/);
gen fi_bmk=0.0868 if year==2019;
replace fi_bmk=-0.005 if year==2018;
replace fi_bmk=0.0353 if year==2017;
replace fi_bmk=0.0256 if year==2016;
replace fi_bmk=0.0048 if year==2015;
replace fi_bmk=0.0604 if year==2014;
replace fi_bmk=-.0215 if year==2013;

** Real estate benchmark is from case-shiller (https://fred.stlouisfed.org/series/CSUSHPINSA) calculated in "Raw Data/Benchmark";
gen real_bmk=0.034 if year==2019;
replace real_bmk=0.056 if year==2018;
replace real_bmk=0.056 if year==2017;
replace real_bmk=0.050 if year==2016;
replace real_bmk=0.045 if year==2015;
replace real_bmk=0.064 if year==2014;
replace real_bmk=0.092 if year==2013;

** Cash benchmark is 3-mth treasury return (http://pages.stern.nyu.edu/~adamodar/New_Home_Page/datafile/histretSP.html);
gen cash_bmk=0.0155 if year==2019;
replace cash_bmk=0.0194 if year==2018;
replace cash_bmk=0.0093 if year==2017;
replace cash_bmk=0.0032 if year==2016;
replace cash_bmk=0.0005 if year==2015;
replace cash_bmk=0.0003 if year==2014;
replace cash_bmk=0.0006 if year==2013;

** PE benchmark is avg. IRR from Preqin for VC/PE/EarlyStage/Growth/Buyout calculated in "Raw Data/Benchmark";
gen pe_bmk=0.1722 if year==2018;
replace pe_bmk=0.1691 if year==2017;
replace pe_bmk=0.1673 if year==2016;
replace pe_bmk=0.1701 if year==2015;
replace pe_bmk=0.1694 if year==2014;
replace pe_bmk=0.1631 if year==2013;

gen retlb_lsw_eqty=ret_lsw_eqty-eqty_bmk if ret_lsw_eqty!=.;
gen retlb_lsw_alt=ret_lsw_alt-pe_bmk if ret_lsw_alt!=.;
gen retlb_lsw_cash=ret_lsw_cash-cash_bmk if ret_lsw_cash!=.;
gen retlb_lsw_fi=ret_lsw_fi-fi_bmk if ret_lsw_fi!=.;
gen retlb_lsw_real=ret_lsw_real-real_bmk if ret_real!=.;
egen avg_bmk=rowmean(eqty_bmk fi_bmk cash_bmk real_bmk pe_bmk);
egen avg_bmk_ex_cash=rowmean(eqty_bmk fi_bmk real_bmk pe_bmk);
egen avg_ret=rowmean(ret_lsw_eqty ret_lsw_alt ret_lsw_cash ret_lsw_fi ret_lsw_real);
egen avg_ret_ex_cash=rowmean(ret_lsw_eqty ret_lsw_alt ret_lsw_fi ret_lsw_real);
egen avg_retlb=rowmean(retlb_lsw_eqty retlb_lsw_alt retlb_lsw_cash retlb_lsw_fi retlb_lsw_real);
egen avg_retlb_ex_cash=rowmean(retlb_lsw_eqty retlb_lsw_alt retlb_lsw_fi retlb_lsw_real);
gen avg_tretlb=ret_tot_val-avg_bmk;
gen avg_tret=ret_tot_val;
gen avg_tret_ex_cash=ret_tot_val_ex_cash;

** Now create a summary of performance relative to the benchmark (i.e., a table like Table 3 Return Decomposition in Lerner et al.);
** We examine investment across five major asset classes: equities, fixed income, real estate, alternatives (which includes hedge funds, commodities such as oil and timber, and private equity buyout and venture funds), and cash;
** At first we just want to replicate a table similar to the panel for All in Table 1 of Lerner, Schoar, and Wang (I have included a copy in folder);
** MEAN;
preserve;
gen count=1;
drop if endow==1;
collapse (sum) count (mean) tot_val plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash 
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at;
** Formatting things to be easier to put into latex;
replace tot_val=tot_val/1000000;
format tot_val %9.1fc;
foreach x in plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at{;
	replace `x'=`x'*100;
	format `x' %9.1fc;
};
gen type="all";
save "avg all.dta", replace;
restore;

** STD DEV.;
preserve;
drop if endow==1;
collapse (sd) tot_val plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at;
replace tot_val=tot_val/1000000;
format tot_val %9.1fc;
rename tot_val sd_tot_val;
foreach x in plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
pst_val plt_val ret_lt_val ret_st_val  inv2at invfees2inv invfees2at{;
	replace `x'=`x'*100;
};	
foreach x in plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash 
pst_val plt_val ret_lt_val ret_st_val  inv2at invfees2inv invfees2at{;
	format `x' %9.1fc;
	rename `x' sd_`x';
};
gen type="all";
save "sd all.dta", replace;
restore;

** NEXT WE WANT TO DO THIS BY VARIOUS CHARACTERISTICS OF DAFs;
preserve;
gen count=1;
drop if endow==1;
keep if style_innov==1;
** note: keeping to append together for unvariate tests;
save "innov_stand_alone.dta", replace;
collapse (sum) count (mean) tot_val plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at;
** Formatting things to be easier to put into latex;
replace tot_val=tot_val/1000000;
format tot_val %9.1fc;
foreach x in plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val  inv2at invfees2inv invfees2at{;
	replace `x'=`x'*100;
	format `x' %9.1fc;
};
gen type="stand_alone_innov";
save "avg innov stand alone.dta", replace;
restore;

preserve;
gen count=1;
drop if endow==1;
keep if style_disrupt==1;
** note: keeping to append together for unvariate tests;
save "disrupt_stand_alone.dta", replace;
collapse (sum) count (mean) tot_val plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at;
** Formatting things to be easier to put into latex;
replace tot_val=tot_val/1000000;
format tot_val %9.1fc;
foreach x in plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at{;
	replace `x'=`x'*100;
	format `x' %9.1fc;
};
gen type="stand_alone_disrupt";
save "avg innov disrupt.dta", replace;
restore;

preserve;
gen count=1;
drop if endow==1;
keep if style_trad==1;
** note: keeping to append together for unvariate tests;
save "trad_stand_alone.dta", replace;
collapse (sum) count (mean) tot_val plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at;
** Formatting things to be easier to put into latex;
replace tot_val=tot_val/1000000;
format tot_val %9.1fc;
foreach x in plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val  inv2at invfees2inv invfees2at{;
	replace `x'=`x'*100;
	format `x' %9.1fc;
};
gen type="stand_alone_trad";
save "avg trad stand alone.dta", replace;
restore;

preserve;
gen count=1;
drop if endow==1;
keep if feature_impact==1;
** note: keeping to append together for unvariate tests;
save "has impact.dta", replace;
collapse (sum) count (mean) tot_val plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at;
** Formatting things to be easier to put into latex;
replace tot_val=tot_val/1000000;
format tot_val %9.1fc;
foreach x in plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret  avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at{;
	replace `x'=`x'*100;
	format `x' %9.1fc;
};
gen type="has impact";
save "avg has impact.dta", replace;
restore;

preserve;
gen count=1;
drop if endow==1;
keep if feature_impact==0;
** note: keeping to append together for unvariate tests;
save "has no impact.dta", replace;
collapse (sum) count (mean) tot_val plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at;
** Formatting things to be easier to put into latex;
replace tot_val=tot_val/1000000;
format tot_val %9.1fc;
foreach x in plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret  avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at{;
	replace `x'=`x'*100;
	format `x' %9.1fc;
};
gen type="has no impact";
save "avg has no impact.dta", replace;
restore;

preserve;
gen count=1;
keep if top20==1;
collapse (sum) count (mean) tot_val plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at;
** Formatting things to be easier to put into latex;
replace tot_val=tot_val/1000000;
format tot_val %9.1fc;
foreach x in plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at{;
	replace `x'=`x'*100;
	format `x' %9.1fc;
};
gen type="top20 endow";
save "avg top20 endow.dta", replace;
restore;

preserve;
gen count=1;
keep if endow==1;
collapse (sum) count (mean) tot_val plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val inv2at invfees2inv invfees2at;
** Formatting things to be easier to put into latex;
replace tot_val=tot_val/1000000;
format tot_val %9.1fc;
foreach x in plsw_cash plsw_eqty plsw_fi plsw_alt plsw_real pimpact_val pvc_val ppe_val phfund_val pcommod_val pderiv_val palt_inv_val
ret_lsw_eqty ret_lsw_fi ret_lsw_cash ret_lsw_real ret_lsw_alt retlb_lsw_eqty retlb_lsw_fi retlb_lsw_cash retlb_lsw_real retlb_lsw_alt avg_ret avg_retlb 
ret_tot_val ret_impact_val ret_vc_val ret_pe_val ret_hfund_val ret_commod_val ret_deriv_val ret_alt_inv_val avg_tretlb avg_tret  avg_tret_ex_cash
plt_val ret_lt_val pst_val ret_st_val  inv2at invfees2inv invfees2at{;
	replace `x'=`x'*100;
	format `x' %9.1fc;
};
gen type="endow";
save "avg endow.dta", replace;
restore;

** COMBINING AND FORMATTING FOR TABLES THE VARIOUS STATS;
** FIRST LOOKING AT ALL NON-ENDOWMENT COMBINED AND RELATIVE TO BENCHMARK;
use "avg all.dta", clear;
merge 1:1 type using "sd all.dta";
keep tot_val sd_tot_val count avg_tret avg_tret_ex_cash sd_avg_tret avg_tretlb
plsw_eqty sd_plsw_eqty ret_lsw_eqty sd_ret_lsw_eqty retlb_lsw_eqty
plsw_fi sd_plsw_fi ret_lsw_fi sd_ret_lsw_fi retlb_lsw_fi
plsw_cash sd_plsw_cash ret_lsw_cash sd_ret_lsw_cash retlb_lsw_cash
plsw_real sd_plsw_real ret_lsw_real sd_ret_lsw_real retlb_lsw_real
plsw_alt sd_plsw_alt ret_lsw_alt sd_ret_lsw_alt retlb_lsw_alt
pimpact_val sd_pimpact_val ret_impact_val sd_ret_impact_val 
pvc_val sd_pvc_val ret_vc_val sd_ret_vc_val
ppe_val sd_ppe_val ret_pe_val sd_ret_pe_val
phfund_val sd_phfund_val ret_hfund_val sd_ret_hfund_val
pcommod_val sd_pcommod_val ret_commod_val	sd_ret_commod_val
pderiv_val sd_pderiv_val ret_deriv sd_ret_deriv
palt_inv_val sd_palt_inv_val ret_alt_inv sd_ret_alt_inv
pst_val sd_pst_val ret_st_val sd_ret_st_val
plt_val sd_plt_val ret_lt_val sd_ret_lt_val
inv2at invfees2inv invfees2at
;


order tot_val sd_tot_val count avg_tret avg_tret_ex_cash sd_avg_tret avg_tretlb 
plsw_eqty sd_plsw_eqty ret_lsw_eqty sd_ret_lsw_eqty retlb_lsw_eqty
plsw_fi sd_plsw_fi ret_lsw_fi sd_ret_lsw_fi retlb_lsw_fi
plsw_cash sd_plsw_cash ret_lsw_cash sd_ret_lsw_cash retlb_lsw_cash
plsw_real sd_plsw_real ret_lsw_real sd_ret_lsw_real retlb_lsw_real
plsw_alt sd_plsw_alt ret_lsw_alt sd_ret_lsw_alt retlb_lsw_alt
pimpact_val sd_pimpact_val ret_impact_val sd_ret_impact_val 
pvc_val sd_pvc_val ret_vc_val sd_ret_vc_val
ppe_val sd_ppe_val ret_pe_val sd_ret_pe_val
phfund_val sd_phfund_val ret_hfund_val sd_ret_hfund_val
pcommod_val sd_pcommod_val ret_commod_val	sd_ret_commod_val
pderiv_val sd_pderiv_val ret_deriv sd_ret_deriv
palt_inv_val sd_palt_inv_val ret_alt_inv sd_ret_alt_inv
pst_val sd_pst_val ret_st_val sd_ret_st_val
plt_val sd_plt_val ret_lt_val sd_ret_lt_val
inv2at invfees2inv invfees2at;
save "All non-endowment DAF investments for Table 3.dta", replace;


** COMBINING BY DAF TYPE TO UNDERSTAND TRENDS;
use "avg trad stand alone.dta", clear;
append using "avg innov stand alone.dta";
append using "avg innov disrupt.dta";
append using "avg has impact.dta";
append using "avg has no impact.dta";
append using "avg endow.dta";

keep type tot_val avg_tret_ex_cash 
plsw_eqty  
plsw_fi  
plsw_cash 
plsw_real  
plsw_alt  
pimpact_val  
pvc_val   
ppe_val  
phfund_val   
pcommod_val 
pderiv_val
palt_inv_val 
pst_val plt_val count
inv2at invfees2inv invfees2at;
 
order type tot_val avg_tret_ex_cash 
plsw_eqty  
plsw_fi  
plsw_cash 
plsw_real  
plsw_alt  
pimpact_val  
pvc_val   
ppe_val  
phfund_val   
pcommod_val 
pderiv_val
palt_inv_val 
pst_val plt_val count
inv2at invfees2inv invfees2at;

save "DAF investments by type of DAF for Table 4.dta", replace;

** Now getting significance for univariate tests by style;
use "trad_stand_alone.dta", clear;
append using "innov_stand_alone.dta";
append using "disrupt_stand_alone.dta";
gen type="trad" if style_trad==1;
replace type="innov" if style_innov==1;
replace type="disrupt" if style_disrupt==1;
tab type, m;
egen group=group(type);
reg tot_val i.group, vce(robust);
testparm i.group, equal;
testparm i.group;

reg avg_tret_ex_cash i.group, vce(robust);
testparm i.group, equal; 
testparm i.group;
reg invfees2inv i.group, vce(robust);
testparm i.group, equal;
testparm i.group;
reg plsw_eqty i.group, vce(robust);
testparm i.group, equal;
testparm i.group;
reg plsw_fi i.group, vce(robust);  
testparm i.group, equal;
testparm i.group;
reg plsw_cash i.group, vce(robust); 
testparm i.group, equal;
testparm i.group;
reg plsw_real i.group, vce(robust);  
testparm i.group, equal;
testparm i.group;
reg plsw_alt i.group, vce(robust);  
testparm i.group, equal;
testparm i.group;
reg pimpact_val i.group, vce(robust);  
testparm i.group, equal;
testparm i.group;
reg pvc_val i.group, vce(robust);   
testparm i.group, equal;
testparm i.group;
reg ppe_val i.group, vce(robust);  
testparm i.group, equal;
testparm i.group;
reg phfund_val i.group, vce(robust);   
testparm i.group, equal;
testparm i.group;
reg pcommod_val i.group, vce(robust); 
testparm i.group, equal;
testparm i.group;
reg pderiv_val i.group, vce(robust);
testparm i.group, equal;
testparm i.group;
reg palt_inv_val i.group, vce(robust); 
testparm i.group, equal;
testparm i.group;
reg pst_val i.group, vce(robust); 
testparm i.group, equal;
testparm i.group;
reg plt_val i.group, vce(robust); 
testparm i.group, equal;
testparm i.group;

** Now getting significance for univariate tests impact vs. no impact;
use "has impact.dta", clear;
append using "has no impact.dta";
rename feature_impact type;
ttest tot_val, by(type); 
ttest avg_tret_ex_cash, by(type); 
ttest invfees2inv, by(type); 
ttest plsw_eqty, by(type); 
ttest plsw_fi, by(type); 
ttest plsw_cash, by(type); 
ttest plsw_real, by(type);   
ttest plsw_alt, by(type);  
ttest pimpact_val, by(type);  
ttest pvc_val, by(type);   
ttest ppe_val, by(type); 
ttest phfund_val, by(type);   
ttest pcommod_val, by(type); 
ttest pderiv_val, by(type); 
ttest palt_inv_val, by(type);  
ttest pst_val, by(type); 
ttest plt_val, by(type); 



log close;
